-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consistent typehints for NLocal
family
#10479
Conversation
One or more of the the following people are requested to review this:
|
@@ -730,7 +715,7 @@ def parameter_bounds(self, bounds: list[tuple[float, float]]) -> None: | |||
|
|||
def add_layer( | |||
self, | |||
other: Union["NLocal", qiskit.circuit.Instruction, QuantumCircuit], | |||
other: QuantumCircuit | qiskit.circuit.Instruction, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QuantumCircuit
includes "NLocal"
therefore I removed the explicit mention
initial_state: Optional[Any] = None, | ||
initial_state: QuantumCircuit | None = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did this change deliberately?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I thought I left a comment on that -- yes this is on purpose, we deprecated Any
a few months ago (it's already gone in some NLocal circuits) but it seems we forgot it here 🙂 Any
was mainly for backwards compatibility with old applications code so we don't need it anymore
def _convert_to_block(self, layer: Any) -> QuantumCircuit: | ||
def _convert_to_block(self, layer: typing.Any) -> QuantumCircuit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any
means "don't type check this", whereas object
is the base of all Python objects. The fact that this function takes either probably indicates that there's some usage of these objects that ought to be tightened up a bit, but it's not a big deal (and out of scope of this PR anyway).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this can probably be changed to Operation
num_qubits: Optional[int] = None, | ||
entanglement: Union[str, List[List[int]], Callable[[int], List[int]]] = "reverse_linear", | ||
num_qubits: int | None = None, | ||
entanglement: str | list[list[int]] | Callable[[int], list[int]] = "full", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a change in default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, that change was not on purpose 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it's always better to do "reverse_linear" and not "full" since it provides the same unitary, but with O(n) CX gates instead of O(n^2)
num_qubits: int | None = None, | ||
rotation_blocks: str | ||
| type | ||
| qiskit.circuit.Instruction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TwoLocal
was missing Instruction
as supported type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming this all passes now, then it's good to me.
* consistent typehints * lint * attempt to fix docs 1/? * fix accidental default change * fix lint * fix , instead of | (cherry picked from commit eda570c) Co-authored-by: Julien Gacon <[email protected]>
* consistent typehints * lint * attempt to fix docs 1/? * fix accidental default change * fix lint * fix , instead of |
Summary
Fixes #10456 and generally use
collections.abc
overtyping
.Details and comments
Also makes the docs more consistent by removing the first line of the
__init__
doc and theTODO
in the Examples section (tracked in #10480).